function ModuleClientInfo(doc, container, width, height, user, date, options) {
  this._doc = doc;
  this._container = container;
  this._width = width;
  this._height = height;
  this._user = user;
  this._date = date;
  this._options = options;
  
  this._createElements();
};

ModuleClientInfo.prototype._createElements = function() {
  this._gui = new ClientInfo(this._doc, this._container, this._width, this._height, this._user, this._date, this._options)._gui;
  
  //Preset
  this._gui.staff.disabled = true;
  
  this._gui.gender.appendChild(new Option(''));
  var genders = Gender.array();
  for (var i = 0, il = genders.length; i < il; i++) {
    var tmp = genders[i];
    this._gui.gender.appendChild(new Option(tmp));
  }
  this._gui.partnership_status.appendChild(new Option(''));
  var partnerships = Partnership.array();
  for (var i = 0, il = partnerships.length; i < il; i++) {
    var tmp = partnerships[i];
    this._gui.partnership_status.appendChild(new Option(tmp));
  }
  //Object
  var client = (this._options && this._options.object) ? this._options.object : pz_client.instance();
  if (!client.id && client.staff == '') {
    client.staff = this._user.account;
  }
  if (!client.id && client.date_birth == 0) {
    client.date_birth = null;
  }
  if (!client.id) {
    client.date_birth = 0;
    client.pass_date_exp = 0;
    client.pass_date_issue = 0;
    client.first_contact_date = 0;
  }
  //Display
  this._gui.name_family.value = client.name_family;
  this._gui.name_first.value = client.name_first;
  this._gui.file_folder_num.value = client.file_folder_num;
  this._gui.date_birth.value = (client.date_birth == 0) ? '' : SimpleDate.format(SimpleDate.fromStamp(client.date_birth, false), false);
  this._gui.nationality.value = client.nationality;
  for (var i = 0, il = this._gui.gender.options.length; i < il; i++) {
    var tmp = this._gui.gender.options[i];
    if (tmp.text == client.gender) {
      this._gui.gender.selectedIndex = i;
    }
  }
  for (var i = 0, il = this._gui.partnership_status.options.length; i < il; i++) {
    var tmp = this._gui.partnership_status.options[i];
    if (tmp.text == client.partnership_status) {
      this._gui.partnership_status.selectedIndex = i;
    }
  }
  this._gui.addr1.value = client.addr1;
  this._gui.addr2.value = client.addr2;
  this._gui.addr3.value = client.addr3;
  this._gui.phone1.value = client.phone1;
  this._gui.phone2.value = client.phone2;
  this._gui.phone3.value = client.phone3;
  this._gui.email.value = client.email;
  this._gui.pass_num.value = client.pass_num;
  this._gui.pass_date_exp.value = (client.pass_date_exp == 0) ? '' : SimpleDate.format(SimpleDate.fromStamp(client.pass_date_exp, false), false);
  this._gui.pass_date_issue.value = (client.pass_date_issue == 0) ? '' : SimpleDate.format(SimpleDate.fromStamp(client.pass_date_issue, false), false);
  this._gui.country_birth.value = client.country_birth;
  this._gui.agent.value = client.agent;
  this._gui.first_contact_date.value = (client.first_contact_date == 0) ? '' : SimpleDate.format(SimpleDate.fromStamp(client.first_contact_date, false), false);
  this._gui.first_contact_detail.value = client.first_contact_detail;
  //Event
  var _self = this;
  this._gui.name_family.onchange = function() { client.name_family = this.value; };
  this._gui.name_first.onchange = function() { client.name_first = this.value; };
  this._gui.file_folder_num.onchange = function() { client.file_folder_num = this.value; };
  this._gui.date_birth.onchange = function() { client.date_birth = this.value; };
  this._gui.date_birth.onclick = function() { _self._selectDate(this, client.date_birth, function(sd) { client.date_birth = SimpleDate.toStamp(sd, false); }, false); };
  this._gui.nationality.onchange = function() { client.nationality = this.value; };
  this._gui.gender.onchange = function() { client.gender = this.options[this.selectedIndex].text; };
  this._gui.partnership_status.onchange = function() { client.partnership_status = this.options[this.selectedIndex].text; };
  this._gui.addr1.onchange = function() { client.addr1 = this.value; };
  this._gui.addr2.onchange = function() { client.addr2 = this.value; };
  this._gui.addr3.onchange = function() { client.addr3 = this.value; };
  this._gui.phone1.onchange = function() { client.phone1 = this.value; };
  this._gui.phone2.onchange = function() { client.phone2 = this.value; };
  this._gui.phone3.onchange = function() { client.phone3 = this.value; };
  this._gui.email.onchange = function() { client.email = this.value; };
  this._gui.pass_num.onchange = function() { client.pass_num = this.value; };
  this._gui.pass_date_exp.onclick = function() { _self._selectDate.call(_self, this, client.pass_date_exp, function(sd) { client.pass_date_exp = SimpleDate.toStamp(sd); }, false); };
  this._gui.pass_date_issue.onclick = function() { _self._selectDate.call(_self, this, client.pass_date_issue, function(sd) { client.pass_date_issue = SimpleDate.toStamp(sd); }, false); };
  this._gui.country_birth.onchange = function() { client.country_birth = this.value; };
  this._gui.agent.onchange = function() { client.agent = this.value; };
  this._gui.staff.onchange = function() { client.staff = this.options[this.selectedIndex].text; };
  this._gui.first_contact_date.onclick = function() { _self._selectDate.call(_self, this, client.first_contact_date, function(sd) { client.first_contact_date = SimpleDate.toStamp(sd); }, false); };
  this._gui.first_contact_detail.onchange = function() { client.first_contact_detail = this.value; };
  //Submit
  
  
  this._client = client;
  this._loadData();
};
ModuleClientInfo.prototype._selectDate = function(display, date, callbackFunc, showTime) {
  var div = document.createElement('div');
  var ds = new DateSelect((date == 0) ? null : SimpleDate.fromStamp(date, false), null, { container: div, showTime: showTime });
  ds._selectFunc = function(sd) { callbackFunc(sd);
                                  if (sd) { 
                                    display.value = SimpleDate.format(sd, showTime);
                                  } else {
                                    display.value = '';
                                  }
                                  popupBox._close();
                                };
  
  var popupBox = new ModulePopupBoxSimple();
  var pos = DOMUtils.findPos(display);
  popupBox._open(div, { pos: [pos[0], pos[1] + 85] });
};

ModuleClientInfo.prototype._loadData = function() {
  this._gui.staff.disabled = true;
  
  this._users = null;
  this._retrieveUsers();
};

ModuleClientInfo.prototype._verifyData = function() {
  if (this._users) {
    this._updateElements();
  }
};

ModuleClientInfo.prototype._retrieveUsers = function() {
  var _self = this;
  new RequestUtils()._read('pz_user', null, null, null, null, null, null, function(result, params) { _self._users = result.data;
                                                                                                     _self._verifyData.call(_self);
                                                                                                   }, null);
};

ModuleClientInfo.prototype._updateElements = function() {
  this._gui.staff.disabled = false;
  for (var i = 0, il = this._users.length; i < il; i++) {
    var tmp = this._users[i].account;
    this._gui.staff.appendChild(new Option(tmp));
    if (tmp == this._client.staff) {
      this._gui.staff.selectedIndex = i;
    }
  }
};
